home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / linux / atari / source / source.lzh / atari-linux-0.01pl3 / kernel / ldt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-05  |  2.4 KB  |  108 lines

  1. /*
  2.  * linux/kernel/ldt.c
  3.  *
  4.  * Copyright (C) 1992 Krishna Balasubramanian and Linus Torvalds
  5.  */
  6.  
  7. #include <linux/config.h>
  8. #include <linux/errno.h>
  9. #include <linux/sched.h>
  10. #include <linux/string.h>
  11. #include <asm/segment.h>
  12. #include <asm/system.h>
  13. #include <linux/ldt.h>
  14.  
  15. #ifdef __i386__
  16. static int read_ldt(void * ptr, unsigned long bytecount)
  17. {
  18.     int error;
  19.     void * address = current->ldt;
  20.     unsigned long size;
  21.  
  22.     if (!ptr)
  23.         return -EINVAL;
  24.     size = PAGE_SIZE;
  25.     if (!address) {
  26.         address = &default_ldt;
  27.         size = sizeof(default_ldt);
  28.     }
  29.     if (size > bytecount)
  30.         size = bytecount;
  31.     error = verify_area(VERIFY_WRITE, ptr, size);
  32.     if (error)
  33.         return error;
  34.     memcpy_tofs(ptr, address, size);
  35.     return size;
  36. }
  37.  
  38. static int write_ldt(void * ptr, unsigned long bytecount)
  39. {
  40.     struct modify_ldt_ldt_s ldt_info;
  41.     unsigned long *lp;
  42.     unsigned long base, limit;
  43.     int error, i;
  44.  
  45.     if (bytecount != sizeof(ldt_info))
  46.         return -EINVAL;
  47.     error = verify_area(VERIFY_READ, ptr, sizeof(ldt_info));
  48.     if (error)
  49.         return error;
  50.  
  51.     memcpy_fromfs(&ldt_info, ptr, sizeof(ldt_info));
  52.  
  53.     if (ldt_info.contents == 3 || ldt_info.entry_number >= 512)
  54.         return -EINVAL;
  55.  
  56.     limit = ldt_info.limit;
  57.     base = ldt_info.base_addr;
  58.     if (ldt_info.limit_in_pages)
  59.         limit *= PAGE_SIZE;
  60.  
  61.     limit += base;
  62.     if (limit < base || limit >= 0xC0000000)
  63.         return -EINVAL;
  64.  
  65.     if (!current->ldt) {
  66.         for (i=1 ; i<NR_TASKS ; i++) {
  67.             if (task[i] == current) {
  68.                 if (!(current->ldt = (struct desc_struct*) get_free_page(GFP_KERNEL)))
  69.                     return -ENOMEM;
  70.                 set_ldt_desc(gdt+(i<<1)+FIRST_LDT_ENTRY, current->ldt, 512);
  71.                 load_ldt(i);
  72.             }
  73.         }
  74.     }
  75.     
  76.     lp = (unsigned long *) ¤t->ldt[ldt_info.entry_number];
  77.        *lp = ((ldt_info.base_addr & 0x0000ffff) << 16) |
  78.           (ldt_info.limit & 0x0ffff);
  79.     *(lp+1) = (ldt_info.base_addr & 0xff000000) |
  80.           ((ldt_info.base_addr & 0x00ff0000)>>16) |
  81.           (ldt_info.limit & 0xf0000) |
  82.           (ldt_info.contents << 10) |
  83.           ((ldt_info.read_exec_only ^ 1) << 9) |
  84.           (ldt_info.seg_32bit << 22) |
  85.           (ldt_info.limit_in_pages << 23) |
  86.           0xf000;
  87.     return 0;
  88. }
  89. #else
  90. static int read_ldt(void * ptr, unsigned long bytecount)
  91. {
  92.     return -ENOSYS;
  93. }
  94. static int write_ldt(void * ptr, unsigned long bytecount)
  95. {
  96.     return -ENOSYS;
  97. }
  98. #endif
  99.  
  100. asmlinkage int sys_modify_ldt(int func, void *ptr, unsigned long bytecount)
  101. {
  102.     if (func == 0)
  103.         return read_ldt(ptr, bytecount);
  104.     if (func == 1)
  105.         return write_ldt(ptr, bytecount);
  106.     return -ENOSYS;
  107. }
  108.